package com.sm.healthy.model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.sm.healthy.utils.CacheUtil
import com.sm.healthy.base.App
import com.sm.healthy.data.bean.Spo2Entity
import com.sm.healthy.ext.gson
import kotlinx.coroutines.launch
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.util.LogUtils

class Spo2ViewModel : BaseViewModel() {
    val TAG = "Spo2ViewModel"
    val spo2Text = StringObservableField("---")
    val pulseRateText = StringObservableField("---")

    val dao = App.database.spo2Dao()
    val spo2Entity = MutableLiveData(Spo2Entity(CacheUtil.getCurUid()))

    fun insert() {
        spo2Entity.value?.let {
            LogUtils.debugInfo(TAG, "data = ${gson.toJson(it)}")
            viewModelScope.launch {
                dao.insert(it)
            }
        }
    }
}